/**
 * 
 */
package com.shanglida.maintabs;

import android.app.SearchManager.OnCancelListener;
import android.os.AsyncTask;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.shanglida.activity.BaseFragment;
import com.shanglida.adapt.NearByPeopleAdapter;
import com.shanglida.entity.NearByPeople;
import com.shanglida.view.RefreshListener;
import com.shanglida.view.RefreshListener.OnRefreshListener;

/**
 * @author liu
 * 
 */
public class NearByPeopleFragment extends BaseFragment implements
		OnItemClickListener, OnRefreshListener, OnCancelListener {

	private RefreshListener mMmrlvList;
	private NearByPeopleAdapter mAdapter;

	public NearByPeopleFragment() {
		super();
	}

	@Override
	protected void initEvents() {
		mMmrlvList.setOnItemClickListener(this);
		mMmrlvList.setOnRefreshListener(this);
	}

	@Override
	protected void init() {
		getPeoples();
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		int position = (int) arg3;
		NearByPeople people = mApplication.mNearByPeoples.get(position);
		String uid = null;
		String name = null;
		String avatar = null;
		if (position > 3) {
			uid = "momo_p_other";
		} else {
			uid = people.getUid();
		}
	}

	private void getPeoples() {
		if (mApplication.mNearByPeoples.isEmpty()) {
			putAsyncTask(new AsyncTask<Void, Void, Boolean>() {

				@Override
				protected void onPreExecute() {
					super.onPreExecute();
					showLoadingDialog("正在加载,请稍后...");
				}

				@Override
				protected Boolean doInBackground(Void... params) {
					return null;
				}

				@Override
				protected void onPostExecute(Boolean result) {
					super.onPostExecute(result);
					dismissLoadingDialog();
					if (!result) {
						showCustomToast("数据加载失败1...");
					} else {
						showCustomToast("数据加载失败2...");
					}
				}

			});
		} else {
			showCustomToast("数据加载失败...");
		}
	}

	@Override
	public void onCancel() {
		clearAsyncTask();
		mMmrlvList.onRefreshComplete();
	}

	@Override
	public void onRefresh() {
		putAsyncTask(new AsyncTask<Void, Void, Boolean>() {

			@Override
			protected Boolean doInBackground(Void... params) {
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {

				}
				return null;
			}

			@Override
			protected void onPostExecute(Boolean result) {
				super.onPostExecute(result);
				mMmrlvList.onRefreshComplete();
			}
		});
	}

	public void onManualRefresh() {
		mMmrlvList.onManualRefresh();
	}

	@Override
	protected void initViews() {
		// TODO Auto-generated method stub

	}

}
